home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / GameboyDev / GBDK / lib / sample.s < prev    next >
Encoding:
Text File  |  1999-03-30  |  1.6 KB  |  97 lines

  1.   .include "global.s"
  2.  
  3.   .title "Sound sample player"
  4.   .module Sample
  5.  
  6.  
  7.   .AUD3WAVERAM = 0xff30
  8.  
  9. _play_sample::
  10.   push bc
  11.   lda hl,4(sp)
  12.   ld a,(hl+)
  13.   ld d,(hl)
  14.   ld e,a
  15.  
  16.   lda hl,6(sp)
  17.   ld a,(hl+)
  18.   ld b,(hl)
  19.   ld c,a
  20.  
  21.   ld h,d
  22.   ld l,e
  23.  
  24.   call .play_sample
  25.   pop bc
  26.   ret
  27.  
  28. ; Playback raw sound sample with length BC from HL at 8192Hz rate.
  29. ; BC defines the length of the sample in samples/32 or bytes/16.
  30. ; The format of the data is unsigned 4-bit samples,
  31. ; 2 samples per byte, upper 4-bits played before lower 4 bits.
  32. ;
  33. ; Adaption for GBDK by Lars Malmborg.
  34. ; Original code by Jeff Frohwein.
  35.  
  36. .play_sample::
  37.   ld  a,#0x84
  38.   ldh (.NR52),a       ;enable sound 3
  39.  
  40.   ld a,#0
  41.   ldh (.NR30),a
  42.   ldh (.NR51),a
  43.  
  44.   ld a,#0x77
  45.   ldh (.NR50),a       ;select speakers
  46.   ld a,#0xff
  47.   ldh (.NR51),a       ;enable sound 3
  48.  
  49.   ld a,#0x80
  50.   ldh (.NR31),a       ;sound length
  51.   ld a,#0x20
  52.   ldh (.NR32),a       ;sound level high
  53.  
  54.   ld a,#0x00
  55.   ldh (.NR33),a       ;sound freq low
  56.  
  57. .samp2:
  58.   ld de,#.AUD3WAVERAM ;12
  59.   push bc             ;16
  60.   ld b,#16            ;16
  61.  
  62.   xor a
  63.   ldh (.NR30),a
  64. .samp3:
  65.   ld a,(hl+)          ;8
  66.   ld (de),a           ;8
  67.   inc de              ;8
  68.   dec b               ;4
  69.   jr nz,.samp3        ;12
  70.  
  71.   ld a,#0x80
  72.   ldh (.NR30),a
  73.  
  74.   ld a,#0x87          ; (256hz)
  75.   ldh (.NR34),a
  76.  
  77.   ld bc,#558          ;delay routine
  78. .samp4:
  79.   dec bc              ;8
  80.   ld a,b              ;4
  81.   or c                ;4
  82.   jr nz,.samp4        ;12
  83.  
  84.   ld a,#0             ;more delay
  85.   ld a,#0
  86.   ld a,#0
  87.  
  88.   pop bc              ;12
  89.   dec bc              ;8
  90.   ld a,b              ;4
  91.   or c                ;4
  92.   jr nz,.samp2        ;12
  93.  
  94.   ld a,#0xbb
  95.   ldh (.NR51),a       ;disable sound 3
  96.   ret
  97.